package com.class4.search_sort.exer3;

import java.util.Arrays;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2024/3/18 16:10
 */
public class BubbleSortTest {
    public static void main(String[] args) {
        int[] arr = {7, 6, 20, 85, 84, 94, 31, 49, 82, 40, 89, 34};
        //遍历
//        for (int i = 0; i < arr.length; i++) {
//            System.out.println("第" + (i + 1) + "次排序：" + arr[i]);
//        }
        //冒泡排序，实现数组元素从小到大排序
        for (int j = 0; j < arr.length - 1; j++) {
            for (int i = 0; i < arr.length - 1 - j; i++) {
                // 判断当前元素是否大于下标为i+1的元素
                if (arr[i] > arr[i + 1]) {
                    int temp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = temp;
                }

            }
        }

        System.out.println(Arrays.toString(arr));
//        test();

    }


//    public static void test() {
//        int a = 1;//苹果汁
//        int b = 3;//香蕉汁
//        int tem = 0;//临时空杯子
//        tem = a;
//        a = b;
//        b = tem;
//        System.out.println("a:" + a);
//        System.out.println("b:" + b);
//
//    }


}
